﻿Imports System.IO

<Serializable()> _
Public Class ObjectTypeTemplate

    Private _ID As Guid
    Public Property ID() As Guid
        Get
            Return _ID
        End Get
        Set(ByVal value As Guid)
            _ID = value
        End Set
    End Property

    Private _Name As String
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Private _ImageName As String
    Public Property ImageName() As String
        Get
            Dim myImageName As String = _ImageName
            If (myImageName Is Nothing) OrElse (myImageName.Trim.Length = 0) Then myImageName = Name & ".png"
            Return myImageName
        End Get
        Set(ByVal value As String)
            _ImageName = value
        End Set
    End Property

    Private _VisioShapeName As String
    Public Property VisioShapeName() As String
        Get
            Return _VisioShapeName
        End Get
        Set(ByVal value As String)
            _VisioShapeName = value
        End Set
    End Property

    Private _IsSystem As Boolean
    Public Property IsSystem() As Boolean
        Get
            Return _IsSystem
        End Get
        Set(ByVal value As Boolean)
            _IsSystem = value
        End Set
    End Property

    Private _ArrayOfProperties As ObjectTypePropertyTemplate()
    Public Property ArrayOfProperties() As ObjectTypePropertyTemplate()
        Get
            Dim myList As ObjectTypePropertyTemplate() = _ArrayOfProperties
            If myList Is Nothing Then
                myList = New List(Of ObjectTypePropertyTemplate)().ToArray
                _ArrayOfProperties = myList
            End If
            Return myList
        End Get
        Set(ByVal value As ObjectTypePropertyTemplate())
            _ArrayOfProperties = value
        End Set
    End Property
    Public Function ListOfProperties() As List(Of ObjectTypePropertyTemplate)
        Dim myList As New List(Of ObjectTypePropertyTemplate)(ArrayOfProperties)
        Return myList
    End Function
    Public Overloads Sub AddProperties(ByVal anArrayOfObjectPropertyTypeTemplate As ObjectTypePropertyTemplate())
        For Each myItem As ObjectTypePropertyTemplate In anArrayOfObjectPropertyTypeTemplate
            AddProperty(myItem)
        Next
    End Sub
    Public Overloads Sub AddProperties(ByVal aListOfObjectPropertyTypeTemplate As List(Of ObjectTypePropertyTemplate))
        For Each myItem As ObjectTypePropertyTemplate In aListOfObjectPropertyTypeTemplate
            AddProperty(myItem)
        Next
    End Sub
    Public Sub AddProperty(ByVal anObjectPropertyTypeTemplate As ObjectTypePropertyTemplate)
        Dim myList As List(Of ObjectTypePropertyTemplate) = ListOfProperties()
        myList.Add(anObjectPropertyTypeTemplate)
        ArrayOfProperties = myList.ToArray
    End Sub

    Private _ArrayOfRelation As Relation()
    Public Property ArrayOfRleation() As Relation()
        Get
            Dim myD As Relation() = _ArrayOfRelation
            If myD Is Nothing Then
                myD = New List(Of Relation)().ToArray
                _ArrayOfRelation = myD
            End If
            Return myD
        End Get
        Set(ByVal value As Relation())
            _ArrayOfRelation = value
        End Set
    End Property
    Public Function ListOfRelations() As List(Of Relation)
        If ArrayOfRleation Is Nothing Then ArrayOfRleation = New List(Of Relation)().ToArray
        Dim myList As New List(Of Relation)(ArrayOfRleation)
        Return myList
    End Function
    Public Sub AddRleation(ByVal anObjectTypeTemplate As ObjectTypeTemplate, ByVal aRelationType As enmRelationType)
        Dim myNewRelation As New Relation
        With myNewRelation
            .ID = Guid.NewGuid()
            .ObjectTypeTemplate_ID = anObjectTypeTemplate.ID
            .RelationType = aRelationType
        End With
        Dim myList As List(Of Relation) = ListOfRelations()
        myList.Add(myNewRelation)
        ArrayOfRleation = myList.ToArray
    End Sub

    Public Overloads Function ToString(ByVal aLevelToIdent As Integer)
        Dim myIdent As String = String.Empty
        For I As Integer = 0 To aLevelToIdent
            myIdent &= vbTab
        Next
        Dim mySW As New StringWriter
        With mySW
            .WriteLine(String.Format("{0}ID                                  {1} ({2})", myIdent, ID, ID.GetType.ToString))
            .WriteLine(String.Format("{0}Name                                {1} ({2})", myIdent, Name, Name.GetType.ToString))
            .WriteLine(String.Format("{0}ImageName                           {1} ({2})", myIdent, ImageName, ImageName.GetType.ToString))
            .WriteLine(String.Format("{0}VisioShapeName                      {1} ({2})", myIdent, VisioShapeName, VisioShapeName.GetType.ToString))
            .WriteLine(String.Format("{0}Number of Properties: {1}", myIdent, ListOfProperties.Count))
            For Each myP As ObjectTypePropertyTemplate In ListOfProperties()
                .WriteLine(myP.ToString(aLevelToIdent + 1))
            Next
            .WriteLine(String.Format("{0}Number of Relations: {1}", myIdent, ListOfRelations.Count))
            For Each myTab As Relation In ListOfRelations()
                .WriteLine(myTab.ToString(aLevelToIdent + 1))
            Next
        End With
        Return mySW.ToString
    End Function

    Public Overrides Function ToString() As String
        Return ToString(0)
    End Function

End Class
